package durst.action.account.include;

import java.sql.SQLException;
import java.util.List;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;

import com.sdicons.json.mapper.JSONMapper;
import com.sdicons.json.mapper.MapperException;

import durst.action.CalendarBasicAction;
import durst.data.Friend;
import durst.data.dao.DaoFactory;
import durst.data.dao.impl.FriendDao;

@UrlBinding(value = "/action/include/friends")
public class FriendsIncludeAction extends CalendarBasicAction {
	@SuppressWarnings("unchecked")
	@DefaultHandler
	public Resolution include() throws SQLException, MapperException {
		List<Friend> friends = ((FriendDao<Friend, Integer>) DaoFactory.getInstance().createDao(
				Friend.class)).getFriends(context.getAccount());

		context.getRequest().setAttribute("friendCount", friends.size());
		context.getRequest().setAttribute("friends", JSONMapper.toJSON(friends).render(false));

		return new ForwardResolution("/account/includes/friends.jsp");
	}
}
